<!DOCTYPE html>

<html class="no-js">

<head>
  <meta charset="utf-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <title></title>
  <meta name="description" content="" />
  <meta name="viewport" content="width=device-width, initial-scale=1" />

  <script src="https://cdn.bootcss.com/axios/0.19.0-beta.1/axios.js"></script>

  <script src="https://cdn.bootcss.com/vue/2.5.17/vue.js"></script>
  <!-- 导入拖拽需要的包 -->
  <script src="https://cdn.bootcss.com/Sortable/1.10.0-rc2/Sortable.min.js"></script>
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/element-ui/2.11.0/theme-chalk/index.css" />
  <script src="https://cdnjs.cloudflare.com/ajax/libs/element-ui/2.11.0/index.js"></script>
  <link rel="stylesheet" href="../../../lib/index.css" />
  <script src="../../../lib/avue.js"></script>
</head>

<body>
  <div id="app">
    {{list}}
    <avue-crud :data="list" :option="option" @sortable-change="sortableChange">
    </avue-crud>
  </div>
</body>
<script>
  new Vue({
    el: '#app',
    data() {
      return {
        list: [
          {
            id: 1,
            name: '张三',
            sex: '男',
            date: '1994-02-23 00:00:00'
          },
          {
            id: 2,
            name: '李四',
            sex: '女',
            date: '1994-02-23 00:00:00'
          },
          {
            id: 3,
            name: '王五',
            sex: '女',
            date: '1994-02-23 00:00:00'
          },
          {
            id: 4,
            name: '赵六',
            sex: '男',
            date: '1994-02-23 00:00:00'
          }
        ],
        option: {
          title: '表格的标题',
          sortable: true,
          dragHandler: true,
          border: true,
          align: 'center',
          menuAlign: 'center',
          column: [
            {
              label: '姓名',
              prop: 'name'
            },
            {
              label: '性别',
              prop: 'sex'
            },
            {
              label: '日期',
              prop: 'date',
              type: 'date',
              format: 'yyyy-MM-dd hh:mm:ss',
              valueFormat: 'yyyy-MM-dd hh:mm:ss'
            },
          ]
        }
      }
    }
    ,
    methods: {
      /**
       * @title 排序后的回调方法
       * @param {Int} oldindex    对象老序号
       * @param {Int} newindex    对象新序号
       * @param {Object} row      移动的对象数据
       * @param {Array} list      排序后的整个对象
       * @param return
       **/
      sortableChange(oldindex, newindex, row, list) {
        this.list = list
        console.log(oldindex, newindex, row, list)
      }
    }
  })
</script>

</html>